<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use app\models\question;
use app\models\topicState;

class QuestionController extends Controller{
      public $enableCsrfValidation = false;
        //2.3 获取问题的题目question
      public function actionGet(){
          $model = new question();
          if(Yii::$app->request->isPost){
             $postData = Yii::$app->request->post();
             $topicId = $postData['topicId'];
        //   $sql = "select topicId, content,type,trueAnswer,answer_a,answer_b,answer_c,answer_d from freshmanHelper_questions where topicId = $topicId";
             $sql = "select * from freshmanHelper_questions where topicId = $topicId";
             $data = question::findBysql($sql)->asArray()->all();
             echo json_encode(array('error' => 0,'message' =>'success','data' =>$data,));
           }
             exit(0);
    }

     public function actionNum(){
             $model = new question();
             $sql = "select count(questionsId) from freshmanHelper_questions";
             $data = question::findBysql($sql)->asArray()->all();
             $data = (int)$data[0]['count(questionsId)'];
             echo json_encode(array('error' => 0,'message' =>'success','QuesttionNum' =>$data,));
             exit(0);
        }
}
